home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3327 < prev    next >
Mailbox/MIME Entity  |  1996-08-06  |  2.6 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: Mailbox/MIME Entity (archive/mbox).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert Newsgroup Content (archive/news) magic Supported
100% dexvert Mailbox/MIME Entity (archive/mbox) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file news text default
99% file C++ source, ASCII text default
100% checkBytes Printable ASCII default
100% dexmagic PrintFox/Pagefox WEAK default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/950 MIME Email (1.0) default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime message/news default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 50 61 74 68 3a 20 6c 69 | 62 72 61 72 79 2e 65 72 |Path: li|brary.er|
|00000010| 63 2e 63 6c 61 72 6b 73 | 6f 6e 2e 65 64 75 21 72 |c.clarks|on.edu!r|
|00000020| 70 69 21 75 73 65 6e 65 | 74 0a 46 72 6f 6d 3a 20 |pi!usene|t.From: |
|00000030| 42 6f 77 64 65 6e 20 57 | 69 73 65 20 3c 77 69 73 |Bowden W|ise <wis|
|00000040| 65 62 40 63 73 2e 72 70 | 69 2e 65 64 75 3e 0a 4e |eb@cs.rp|i.edu>.N|
|00000050| 65 77 73 67 72 6f 75 70 | 73 3a 20 63 6f 6d 70 2e |ewsgroup|s: comp.|
|00000060| 6c 61 6e 67 2e 63 2b 2b | 0a 53 75 62 6a 65 63 74 |lang.c++|.Subject|
|00000070| 3a 20 52 65 3a 20 56 65 | 63 74 6f 72 20 6f 66 20 |: Re: Ve|ctor of |
|00000080| 61 62 73 74 72 61 63 74 | 20 63 6c 61 73 73 65 73 |abstract| classes|
|00000090| 20 75 73 69 6e 67 20 53 | 54 4c 0a 44 61 74 65 3a | using S|TL.Date:|
|000000a0| 20 4d 6f 6e 2c 20 32 32 | 20 4a 61 6e 20 31 39 39 | Mon, 22| Jan 199|
|000000b0| 36 20 31 31 3a 30 33 3a | 31 36 20 2d 30 38 30 30 |6 11:03:|16 -0800|
|000000c0| 0a 4f 72 67 61 6e 69 7a | 61 74 69 6f 6e 3a 20 52 |.Organiz|ation: R|
|000000d0| 65 6e 73 73 65 6c 61 65 | 72 20 50 6f 6c 79 74 65 |ensselae|r Polyte|
|000000e0| 63 68 6e 69 63 20 49 6e | 73 74 69 74 75 74 65 2c |chnic In|stitute,|
|000000f0| 20 43 6f 6d 70 75 74 65 | 72 20 53 63 69 65 6e 63 | Compute|r Scienc|
|00000100| 65 0a 4d 65 73 73 61 67 | 65 2d 49 44 3a 20 3c 33 |e.Messag|e-ID: <3|
|00000110| 31 30 33 44 46 37 34 2e | 32 43 37 31 40 63 73 2e |103DF74.|2C71@cs.|
|00000120| 72 70 69 2e 65 64 75 3e | 0a 52 65 66 65 72 65 6e |rpi.edu>|.Referen|
|00000130| 63 65 73 3a 20 3c 33 31 | 30 33 36 39 39 41 2e 37 |ces: <31|03699A.7|
|00000140| 39 46 38 40 63 65 2e 6b | 74 68 2e 73 65 3e 0a 4e |9F8@ce.k|th.se>.N|
|00000150| 4e 54 50 2d 50 6f 73 74 | 69 6e 67 2d 48 6f 73 74 |NTP-Post|ing-Host|
|00000160| 3a 20 68 6f 6f 76 65 72 | 2e 63 73 2e 72 70 69 2e |: hoover|.cs.rpi.|
|00000170| 65 64 75 0a 4d 69 6d 65 | 2d 56 65 72 73 69 6f 6e |edu.Mime|-Version|
|00000180| 3a 20 31 2e 30 0a 43 6f | 6e 74 65 6e 74 2d 54 79 |: 1.0.Co|ntent-Ty|
|00000190| 70 65 3a 20 74 65 78 74 | 2f 70 6c 61 69 6e 3b 20 |pe: text|/plain; |
|000001a0| 63 68 61 72 73 65 74 3d | 75 73 2d 61 73 63 69 69 |charset=|us-ascii|
|000001b0| 0a 43 6f 6e 74 65 6e 74 | 2d 54 72 61 6e 73 66 65 |.Content|-Transfe|
|000001c0| 72 2d 45 6e 63 6f 64 69 | 6e 67 3a 20 37 62 69 74 |r-Encodi|ng: 7bit|
|000001d0| 0a 58 2d 4d 61 69 6c 65 | 72 3a 20 4d 6f 7a 69 6c |.X-Maile|r: Mozil|
|000001e0| 6c 61 20 32 2e 30 62 36 | 61 20 28 57 69 6e 31 36 |la 2.0b6|a (Win16|
|000001f0| 3b 20 49 29 0a 54 6f 3a | 20 41 6e 64 65 72 73 20 |; I).To:| Anders |
|00000200| 4f 6c 73 73 6f 6e 20 3c | 61 6f 6c 73 73 6f 6e 40 |Olsson <|aolsson@|
|00000210| 63 65 2e 6b 74 68 2e 73 | 65 3e 0a 0a 41 6e 64 65 |ce.kth.s|e>..Ande|
|00000220| 72 73 20 4f 6c 73 73 6f | 6e 20 77 72 6f 74 65 3a |rs Olsso|n wrote:|
|00000230| 0a 3e 20 0a 3e 20 49 27 | 6d 20 6e 65 77 20 74 6f |.> .> I'|m new to|
|00000240| 20 53 54 4c 20 61 6e 64 | 20 68 61 76 65 20 61 20 | STL and| have a |
|00000250| 71 75 65 73 74 69 6f 6e | 20 61 62 6f 75 74 20 76 |question| about v|
|00000260| 65 63 74 6f 72 73 2e 0a | 3e 20 0a 3e 20 49 20 68 |ectors..|> .> I h|
|00000270| 61 76 65 20 61 6e 20 61 | 62 73 74 72 61 63 74 20 |ave an a|bstract |
|00000280| 63 6c 61 73 73 20 53 68 | 61 70 65 2c 20 74 68 61 |class Sh|ape, tha|
|00000290| 74 20 68 61 73 20 70 75 | 72 65 20 76 69 72 74 75 |t has pu|re virtu|
|000002a0| 61 6c 20 66 75 6e 63 74 | 69 6f 6e 73 2e 0a 3e 20 |al funct|ions..> |
|000002b0| 46 72 6f 6d 20 74 68 69 | 73 20 63 6c 61 73 73 20 |From thi|s class |
|000002c0| 49 20 64 65 72 69 76 65 | 20 72 65 63 74 61 6e 67 |I derive| rectang|
|000002d0| 6c 65 20 61 6e 64 20 63 | 69 72 63 6c 65 20 63 6c |le and c|ircle cl|
|000002e0| 61 73 73 65 73 2e 0a 3e | 20 49 20 77 61 6e 74 20 |asses..>| I want |
|000002f0| 74 6f 20 75 73 65 20 61 | 20 76 65 63 74 6f 72 20 |to use a| vector |
|00000300| 66 6f 72 20 73 74 6f 72 | 69 6e 67 20 74 68 65 20 |for stor|ing the |
|00000310| 73 68 61 70 65 73 2e 0a | 3e 20 0a 3e 20 49 27 76 |shapes..|> .> I'v|
|00000320| 65 20 74 72 69 65 64 20 | 75 73 69 6e 67 20 61 20 |e tried |using a |
|00000330| 76 65 63 74 6f 72 3c 53 | 68 61 70 65 3e 2c 20 62 |vector<S|hape>, b|
|00000340| 75 74 20 49 20 67 65 74 | 20 63 6f 6d 70 69 6c 65 |ut I get| compile|
|00000350| 72 20 65 72 72 6f 72 73 | 20 62 65 63 61 75 73 65 |r errors| because|
|00000360| 0a 3e 20 74 68 65 20 53 | 68 61 70 65 20 63 6c 61 |.> the S|hape cla|
|00000370| 73 73 20 63 61 6e 6e 6f | 74 20 62 65 20 69 6e 73 |ss canno|t be ins|
|00000380| 74 61 6e 74 69 61 74 65 | 64 2e 20 54 68 69 73 20 |tantiate|d. This |
|00000390| 6d 75 73 74 20 62 65 20 | 74 68 65 20 77 72 6f 6e |must be |the wron|
|000003a0| 67 20 77 61 79 20 6f 66 | 0a 3e 20 64 6f 69 6e 67 |g way of|.> doing|
|000003b0| 20 69 74 20 49 20 75 6e | 64 65 72 73 74 61 6e 64 | it I un|derstand|
|000003c0| 2e 0a 3e 20 0a 0a 59 6f | 75 20 6d 75 73 74 20 65 |..> ..Yo|u must e|
|000003d0| 69 74 68 65 72 20 73 74 | 6f 72 65 20 73 68 61 70 |ither st|ore shap|
|000003e0| 65 20 72 65 66 65 72 65 | 6e 63 65 73 20 28 53 68 |e refere|nces (Sh|
|000003f0| 61 70 65 26 29 20 6f 72 | 20 73 68 61 70 65 20 70 |ape&) or| shape p|
|00000400| 6f 69 6e 74 65 72 73 0a | 28 53 68 61 70 65 2a 29 |ointers.|(Shape*)|
|00000410| 20 69 6e 20 74 68 65 20 | 63 6f 6e 74 61 69 6e 65 | in the |containe|
|00000420| 72 20 66 6f 72 20 79 6f | 75 72 20 70 75 72 70 6f |r for yo|ur purpo|
|00000430| 73 65 73 20 69 6e 20 6f | 72 64 65 72 20 74 6f 20 |ses in o|rder to |
|00000440| 67 61 69 6e 20 74 68 65 | 20 62 65 6e 65 66 69 74 |gain the| benefit|
|00000450| 0a 6f 66 20 76 69 72 74 | 75 61 6c 20 66 75 6e 63 |.of virt|ual func|
|00000460| 74 69 6f 6e 73 20 77 68 | 65 6e 20 61 63 63 65 73 |tions wh|en acces|
|00000470| 73 69 6e 67 20 74 68 65 | 20 73 68 61 70 65 73 20 |sing the| shapes |
|00000480| 76 69 61 20 74 68 65 20 | 63 6f 75 6e 74 61 69 6e |via the |countain|
|00000490| 65 72 2e 0a 0a 59 6f 75 | 20 67 65 74 20 74 68 65 |er...You| get the|
|000004a0| 20 63 6f 6d 70 69 6c 65 | 20 65 72 72 6f 72 20 62 | compile| error b|
|000004b0| 65 63 61 75 73 65 20 53 | 68 61 70 65 20 69 73 20 |ecause S|hape is |
|000004c0| 61 62 73 74 72 61 63 74 | 3b 20 79 6f 75 20 63 61 |abstract|; you ca|
|000004d0| 6e 74 20 63 72 65 61 74 | 65 0a 61 6e 20 6f 62 6a |nt creat|e.an obj|
|000004e0| 65 63 74 20 6f 66 20 61 | 6e 20 61 62 73 74 72 61 |ect of a|n abstra|
|000004f0| 63 74 20 63 6c 61 73 73 | 2c 20 68 6f 77 65 76 65 |ct class|, howeve|
|00000500| 72 2c 20 79 6f 75 20 6d | 61 79 20 73 74 6f 72 65 |r, you m|ay store|
|00000510| 20 72 65 66 65 72 65 6e | 63 65 73 0a 61 6e 64 20 | referen|ces.and |
|00000520| 70 6f 69 6e 74 65 72 73 | 20 6f 66 20 61 20 62 61 |pointers| of a ba|
|00000530| 73 65 20 63 6c 61 73 73 | 2c 20 77 68 69 63 68 20 |se class|, which |
|00000540| 70 6f 69 6e 74 73 20 74 | 6f 20 61 6e 20 61 63 74 |points t|o an act|
|00000550| 75 61 6c 79 20 63 6f 6e | 63 72 65 74 65 2c 0a 64 |ualy con|crete,.d|
|00000560| 65 72 69 76 65 64 20 63 | 6c 61 73 73 2e 0a 0a 3e |erived c|lass...>|
|00000570| 20 49 20 74 68 69 6e 6b | 20 49 20 68 61 76 65 20 | I think| I have |
|00000580| 74 6f 20 75 73 65 20 61 | 20 76 65 63 74 6f 72 3c |to use a| vector<|
|00000590| 53 68 61 70 65 2a 3e 20 | 62 75 74 20 64 6f 65 73 |Shape*> |but does|
|000005a0| 20 74 68 65 20 76 65 63 | 74 6f 72 20 64 65 6c 65 | the vec|tor dele|
|000005b0| 74 65 0a 3e 20 74 68 65 | 20 73 68 61 70 65 20 65 |te.> the| shape e|
|000005c0| 6c 65 6d 65 6e 74 73 20 | 77 68 65 6e 20 74 68 65 |lements |when the|
|000005d0| 20 70 72 6f 67 72 61 6d | 20 66 69 6e 69 73 68 65 | program| finishe|
|000005e0| 73 3f 0a 0a 59 6f 75 20 | 61 72 65 20 63 6f 72 72 |s?..You |are corr|
|000005f0| 65 63 74 2e 20 20 54 68 | 65 20 53 54 4c 20 64 6f |ect. Th|e STL do|
|00000600| 65 73 20 4e 4f 54 20 64 | 65 6c 65 74 65 20 74 68 |es NOT d|elete th|
|00000610| 65 20 73 68 61 70 65 20 | 65 6c 65 6d 65 6e 74 73 |e shape |elements|
|00000620| 2e 20 20 54 68 65 0a 53 | 54 4c 20 74 61 6b 65 73 |. The.S|TL takes|
|00000630| 20 63 61 72 65 20 6f 66 | 20 64 65 6c 65 74 69 6e | care of| deletin|
|00000640| 67 20 74 68 65 20 65 6c | 65 6d 65 6e 74 73 20 69 |g the el|ements i|
|00000650| 6e 20 74 68 65 20 63 6f | 6e 74 61 69 6e 65 72 2c |n the co|ntainer,|
|00000660| 20 62 75 74 20 6e 6f 74 | 0a 77 68 61 74 20 74 68 | but not|.what th|
|00000670| 6f 73 65 20 70 6f 69 6e | 74 65 72 73 20 70 6f 69 |ose poin|ters poi|
|00000680| 6e 74 20 74 6f 2e 20 20 | 59 6f 75 20 63 61 6e 20 |nt to. |You can |
|00000690| 65 69 74 68 65 72 20 64 | 65 6c 65 74 65 20 74 68 |either d|elete th|
|000006a0| 65 20 73 68 61 70 65 73 | 0a 79 6f 75 72 73 65 6c |e shapes|.yoursel|
|000006b0| 66 20 62 65 66 6f 72 65 | 20 74 68 65 20 70 72 6f |f before| the pro|
|000006c0| 67 72 61 6d 20 74 65 72 | 6d 69 6e 61 74 65 73 2e |gram ter|minates.|
|000006d0| 20 20 0a 0a 4f 72 2c 20 | 79 6f 75 20 6d 61 79 20 | ..Or, |you may |
|000006e0| 61 64 64 20 74 68 65 20 | 66 6f 6c 6c 6f 77 69 6e |add the |followin|
|000006f0| 67 20 74 6f 20 79 6f 75 | 72 20 53 68 61 70 65 20 |g to you|r Shape |
|00000700| 68 65 61 64 65 72 3a 0a | 0a 76 6f 69 64 20 64 65 |header:.|.void de|
|00000710| 73 74 72 6f 79 20 28 53 | 68 61 70 65 2a 2a 20 70 |stroy (S|hape** p|
|00000720| 74 72 29 20 7b 20 64 65 | 6c 65 74 65 20 2a 70 74 |tr) { de|lete *pt|
|00000730| 72 3b 20 7d 0a 0a 41 6e | 6f 74 65 72 20 69 64 65 |r; }..An|oter ide|
|00000740| 61 20 69 73 20 74 6f 20 | 69 74 65 72 61 74 65 20 |a is to |iterate |
|00000750| 74 68 72 6f 75 67 68 20 | 79 6f 75 72 20 63 6f 6e |through |your con|
|00000760| 74 61 69 6e 65 72 20 61 | 6e 64 20 64 65 6c 65 74 |tainer a|nd delet|
|00000770| 65 0a 65 61 63 68 20 69 | 74 65 6d 20 28 74 68 69 |e.each i|tem (thi|
|00000780| 73 20 69 73 20 74 61 6b | 65 6e 20 66 72 6f 6d 20 |s is tak|en from |
|00000790| 74 68 65 20 6e 65 77 20 | 53 54 4c 20 63 6f 6c 75 |the new |STL colu|
|000007a0| 6d 6e 2c 20 22 53 54 4c | 20 69 6e 20 41 63 74 69 |mn, "STL| in Acti|
|000007b0| 6f 6e 22 2c 20 0a 62 79 | 20 47 72 61 68 61 6d 20 |on", .by| Graham |
|000007c0| 47 6c 61 73 73 2c 20 61 | 70 70 65 61 72 69 6e 67 |Glass, a|ppearing|
|000007d0| 20 69 6e 20 43 2b 2b 20 | 52 65 70 6f 72 74 2c 20 | in C++ |Report, |
|000007e0| 4a 61 6e 20 39 36 2c 20 | 70 70 31 38 2b 2b 29 0a |Jan 96, |pp18++).|
|000007f0| 0a 74 65 6d 70 6c 61 74 | 65 20 3c 63 6c 61 73 73 |.templat|e <class|
|00000800| 20 54 3e 0a 69 6e 6c 69 | 6e 65 20 76 6f 69 64 0a | T>.inli|ne void.|
|00000810| 65 7a 5f 72 65 6c 65 61 | 73 65 20 28 43 6f 6e 74 |ez_relea|se (Cont|
|00000820| 61 69 6e 65 72 26 20 63 | 29 0a 7b 0a 20 20 20 43 |ainer& c|).{. C|
|00000830| 6f 6e 74 61 69 6e 65 72 | 3a 3a 69 74 65 72 61 74 |ontainer|::iterat|
|00000840| 6f 72 20 69 3b 0a 20 20 | 20 66 6f 72 20 28 69 20 |or i;. | for (i |
|00000850| 3d 20 63 2e 62 65 67 69 | 6e 28 29 3b 20 69 20 21 |= c.begi|n(); i !|
|00000860| 3d 20 63 2e 65 6e 64 28 | 29 3b 20 69 2b 2b 29 0a |= c.end(|); i++).|
|00000870| 20 20 20 7b 0a 20 20 20 | 20 20 20 20 64 65 6c 65 | {. | dele|
|00000880| 74 65 20 2a 69 3b 0a 20 | 20 20 7d 0a 7d 0a 0a 53 |te *i;. | }.}..S|
|00000890| 6f 20 62 65 66 6f 72 65 | 20 79 6f 75 72 20 70 72 |o before| your pr|
|000008a0| 6f 67 72 61 6d 20 65 78 | 65 63 75 74 65 73 2c 20 |ogram ex|ecutes, |
|000008b0| 79 6f 75 20 77 6f 75 6c | 64 20 63 61 6c 6c 3a 0a |you woul|d call:.|
|000008c0| 0a 20 20 65 7a 5f 72 65 | 6c 65 61 73 65 20 28 73 |. ez_re|lease (s|
|000008d0| 68 61 70 65 43 6f 6e 74 | 61 69 6e 65 72 29 3b 0a |hapeCont|ainer);.|
|000008e0| 0a 49 20 68 61 76 65 20 | 70 75 74 20 74 6f 67 65 |.I have |put toge|
|000008f0| 74 68 65 72 20 73 65 76 | 65 72 61 6c 20 6e 6f 74 |ther sev|eral not|
|00000900| 65 73 20 6f 6e 20 75 73 | 69 6e 67 20 53 54 4c 20 |es on us|ing STL |
|00000910| 77 69 74 68 20 42 6f 72 | 6c 61 6e 64 2f 4f 57 4c |with Bor|land/OWL|
|00000920| 0a 74 61 6b 65 20 61 20 | 6c 6f 6f 6b 20 61 74 3a |.take a |look at:|
|00000930| 0a 0a 20 20 20 68 74 74 | 70 3a 2f 2f 77 77 77 2e |.. htt|p://www.|
|00000940| 63 73 2e 72 70 69 2e 65 | 64 75 2f 7e 77 69 73 65 |cs.rpi.e|du/~wise|
|00000950| 62 2f 73 74 6c 2d 62 6f | 72 6c 61 6e 64 2e 68 74 |b/stl-bo|rland.ht|
|00000960| 6d 6c 0a 0a 73 65 65 20 | 61 6c 73 6f 0a 0a 20 20 |ml..see |also.. |
|00000970| 20 68 74 74 70 3a 2f 2f | 77 77 77 2e 63 73 2e 72 | http://|www.cs.r|
|00000980| 70 69 2e 65 64 75 2f 7e | 77 69 73 65 62 2f 73 74 |pi.edu/~|wiseb/st|
|00000990| 6c 2d 6e 6f 74 65 73 2e | 68 74 6d 6c 0a 0a 2d 2d |l-notes.|html..--|
|000009a0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000009b0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000009c0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000009d0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000009e0| 2d 2d 0a 47 2e 20 42 6f | 77 64 65 6e 20 57 69 73 |--.G. Bo|wden Wis|
|000009f0| 65 0a 43 6f 6d 70 75 74 | 65 72 20 53 63 69 65 6e |e.Comput|er Scien|
|00000a00| 63 65 20 44 65 70 74 2c | 20 52 65 6e 73 73 65 6c |ce Dept,| Renssel|
|00000a10| 61 65 72 20 50 6f 6c 79 | 74 65 63 68 6e 69 63 20 |aer Poly|technic |
|00000a20| 49 6e 73 74 2c 20 54 72 | 6f 79 2c 20 4e 59 20 31 |Inst, Tr|oy, NY 1|
|00000a30| 32 31 38 30 0a 45 6d 61 | 69 6c 3a 20 77 69 73 65 |2180.Ema|il: wise|
|00000a40| 62 40 63 73 2e 72 70 69 | 2e 65 64 75 20 20 20 20 |b@cs.rpi|.edu |
|00000a50| 20 20 20 20 20 57 57 57 | 3a 20 68 74 74 70 3a 2f | WWW|: http:/|
|00000a60| 2f 77 77 77 2e 63 73 2e | 72 70 69 2e 65 64 75 2f |/www.cs.|rpi.edu/|
|00000a70| 7e 77 69 73 65 62 2f 0a | |~wiseb/.| |
+--------+-------------------------+-------------------------+--------+--------+